import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import Layout from "../views/layout.vue";

//增加routes内的额外配置项
export type AppRouteRecordRaw = RouteRecordRaw & {
    hidden?:boolean
}
const routes = [
    {
        path: "/login",
        name: "Login",
        hidden:true,
        meta: {
            title: '登录'
        },
        component: () => import("../views/Login.vue")
    },{
        path: "/:pathMatch(.*)*",
        hidden:true,
		meta: {
			title: '404页面不存在'
		},
        component: () => import ("../views/404.vue")
    },{
        path: "/",
        name:"/",
        redirect: '/index',
        component: Layout,
        children: [
            {
                path: "index",
                name: "index",
                meta: {
                    title: '首页',
                    icon:"icon-icon_home_fill"
                },
                component: () => import("@/views/index.vue")
            }
        ]
    },{
        path: "/member",
        name: "Member",
        redirect: '/member/list',
        meta: {
            title: '用户管理',
            icon:"icon-7"
        },
        component: Layout,
        children: [
            {
                path: "list",
                name: "memberList",
                meta: {
                    title: '用户列表'
                },
                component: () => import("@/views/user/list.vue")
            },
            {
                path: "details",
                name: "memberDetails",
                hidden:true,
                meta: {
                    title: '用户详情'
                },
                component: () => import("@/views/user/details.vue")
            },
        ]
    }
];

const router = createRouter({
    history: createWebHashHistory(),
    routes: routes as AppRouteRecordRaw[]
})

router.beforeEach((to, from, next)=>{
    document.title = `${to.meta.title}`;
    const role = localStorage.getItem('kaibanApplets_name');
    if (!role && to.path !== '/login') {
        next('/login');
    } else {
        next();
    }
})

export default router